<template>
	<view class="column-levelCenter" style="padding: 20px; height: 100%;">
		<view class="column-levelCenter" style="margin-top: 200px;">
			<view class="" style="margin-bottom: 20px; font-size: 18px;">
				资源分享管理系统
			</view>
			<view class="inputView row-lineConter">
				<uni-icons  type="person-filled" size="20" color="#1E90FF"></uni-icons>
				<view class="" style="margin-left: 8px;">
					<input type="text" placeholder="请输入账号" v-model="account" />
				</view>
			</view>
			
			<view class="inputView row-lineConter" style="margin-top: 10px;">
				<uni-icons  type="locked-filled" size="20" color="#1E90FF"></uni-icons>
				<view class="" style="margin-left: 8px;">
					<input type="text" placeholder="请输入密码" v-model="password" />
				</view>
			</view>
			
			<view @click="loginClick()" class="zsConter mainBgColor" style="margin-top: 50px; border-radius: 8px; width: 200px; height: 44px; color: white; font-size: 18px;">
				登录
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account:null,
				password:null
			}
		},
		onLoad() {
			
			// uni.hideTopWindow()
		},
		onShow() {
			console.log('hideLeftWindow==');
			
			
		},
		methods: {
			loginClick(){
			
					uni.showLoading({
					title:'登录中...'
				})
				var that = this;
				this.$uniCloudApi.query_admin_data(this.account).then(res=>{
					uni.hideLoading();
					console.log('res==',res);
					var password = res.data.password
					if(password == this.password){
						that.$showToast('登录成功');
						that.saveLocalUserInfo();
					} else {
						this.$showToast('密码错误');
					}
				}).catch(res=>{
					uni.hideLoading();
					this.$showToast(res);
				})
			},
			saveLocalUserInfo() {
				var userInfo ={
					"account":this.account,
					"password":this.password
				}
				var that = this;
				that.$setUserInfo(userInfo);
				// uni.$emit('loginSuccess',{"success":true});
				var url = '../add-resource-page/add-resource-page';
				uni.redirectTo({
					url: url,
					fail: () => {
						uni.showModal({
							title: '提示',
							content: '页面 ' + url + ' 跳转失败',
							showCancel: false
						})
					}
				})	
				
				
			// 	uni.setStorage({
			// 		key: 'userInfo',
			// 		data: userInfo,
			// 		success(lres) {
			// 			that.$setUserInfo(userInfo);
			// 			console.log('存本地成功=', lres)
			// 		},
			// 		fail(failres) {
			// 			console.log('存本地失败=', failres)
			// 		}
			
			// 	})
			}
		}
	}
</script>

<style lang="scss" scoped>
  .inputView{
	  height: 40px;
	  width: 180px;
	  padding: 0px 8px;
	  background-color: #F5F5F5;
	  border-radius: 6px;
	  border: 1px solid rgb(239, 239, 239);
  }
</style>
